<template>
  <div  v-bind="$attrs" v-on="$listeners" >
    <el-button icon="el-icon-plus" type="primary" size="small" @click="toAddRecord()"   >回访记录</el-button>
    <add-recode-dialog  v-if="visible" :visible.sync="visible" :id="id"  :row = "recordRow" @reloadList="getCallBack"></add-recode-dialog>
    <el-table
      class="goodList"
      :data="recordList"
      style="width: 100%">
      <el-table-column
        prop="content"
        label="回访记录">
      </el-table-column>
      <el-table-column
        prop="gmt_modified"
        :formatter="timeFormatter"
        label="回访日期"
        width="140px">
      </el-table-column>
      <el-table-column
        label="操作" width="100px">
        <template slot-scope="{row}">
          <el-button type="text" size="mini" @click="toAddRecord(row)">编辑</el-button>
          <el-button type="text" size="mini" @click="delRecord(row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {subTime} from "@/utils/common";
import list from "@/api/onlineRepair/list/index"
import AddRecodeDialog from "./addRecodeDialog";
export default {
  name: "recodeDialog",
  components: {AddRecodeDialog},
  props:["id"],
  data(){
    return{
      recordList:[],
      recordRow:{
        content:undefined
      },
      visible:false
    }
  },
  created() {
    this.getCallBack()
  },
  methods:{
    delRecord(id){
      this.$confirm("确定删除此条回访记录吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        list.delCallBack(this.id,id).then(res=>{
          this.msgSuccess(res.data.msg)
          this.getCallBack()
        })
      });

    },
    timeFormatter(row){
      return subTime(row.gmt_modified)
    },
    getCallBack(){
      list.getCallBack(this.id).then(res=>{
        this.recordList = res.data.value
      })
    },
    toAddRecord(row){
      this.recordRow = row ? row : undefined
      this.visible = true
    },
  }

}
</script>

<style scoped>

</style>
